import tkinter as tk
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
#创建文本输入框
tk.Label(window,text="账号").pack()
text = tk.Entry(window).pack()
window.mainloop()






# 输入默认文本
import tkinter as tk
window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
#创建文本输入框
tk.Label(window,text="账号").pack()
text = tk.Entry(window)
text.pack()
text.delete(0,"end")
text.insert(0,"这里是默认值")
window.mainloop()



# 获取文本值
import tkinter as tk

def A():
    param = text.get()
    print("选中的值",param)

window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
#创建文本输入框
tk.Label(window,text="账号").pack()
text = tk.Entry(window)
text.pack()
tk.Button(window,text="获取文本值",command=A).pack()
window.mainloop()



# 使用textvariable绑定值

import tkinter as tk

def A():
    param = text.get()
    print("选中的值",param)

window = tk.Tk()
window.title('hello thinter')
height= window.winfo_screenheight()
width= window.winfo_screenwidth()
window.geometry('400x300+%d+%d'%((width-400)/2,(height-300)/2))
#创建文本输入框
tk.Label(window,text="账号").pack()
v = tk.StringVar()
text = tk.Entry(window,textvariable=v) #使用textvariable绑定v
v.set("hello!")
text.pack()
tk.Button(window,text="获取文本值",command=A).pack()
window.mainloop()
